package com.xing.binbackend.pattern.responsibility.ecommerce.pay;

// 抽象处理者
public abstract class OrderHandler {
    private OrderHandler next;

    public OrderHandler linkWith(OrderHandler next) {
        this.next = next;
        return next;
    }

    public void handle(OrderRequest order) {
        if (doHandle(order)) {
            return;  // 处理成功则终止
        }
        if (next != null) {
            next.handle(order);
        } else {
            throw new IllegalStateException("处理链终止");
        }
    }

    protected abstract boolean doHandle(OrderRequest order);
}
